package chatGUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JTextPane;

import chatController.ChatController;
import chatModel.ChatModel;
import chatModel.Conversation;
import chatModel.User;
import chatModel.ChatModel.Val;
import signals.SignalTooBigException;
/* 
 * @author deepali and vansh
 */

@SuppressWarnings("unused")

public class ChatGui implements Observer {

    /**
     * @param conWin this parameter is the instance of the connection window
     * that we use
     * @param chatWin this parameter is the instance of the chat window that we
     * use
     * @param cc this parameter is the instance of the chat controller that we
     * use in this chat system
     * @param cm this parameter is the instance of the chat Model that we use in
     * this chat system
     */

    private ConnectionWindow conWin;
    private ChatWindow chatwin;
    public ChatController cc;
    public ChatModel cm;

    /**
     * It calls setbuttonpressed method form chat controller (user presses a
     * button to accept or reject a file proposal)
     */
    public void buttonpressed() {
        cc.setbuttonpressed();
    }

    public ChatGui(ChatModel cm) {
        this.cm = cm;
        conWin = new ConnectionWindow(this);
    }

    /**
     * sets the gui for answering the file
     *
     * @param username
     * @param filename
     * @param accepted
     */
    public void GUIAnswerFile(String username, String filename, boolean accepted) {
        cc.performSendFileAnswer(username, filename, accepted);
    }

    /**
     * sets the filetransfer window
     *
     * @param username
     * @param filename
     */
    public void FileWindow(String username, String filename) {
        System.out.println("File Window Open");
        FileNotifWindow fnw = new FileNotifWindow(username, filename, this);
    }

    /**
     * Sets current chat controller
     *
     * @param cc
     */
    public void setCc(ChatController cc) {
        this.cc = cc;
    }

    /**
     * This method allows us to connect, we use the chat controller to do get
     * connected
     *
     * @param username
     */
    public void connect(String username) throws SignalTooBigException {
        cc.performConnect(username);
    }

    /**
     * the method closes the window and exits
     */
    public void close() {
        System.exit(0);
    }

    /**
     * This method allows us to add a tab in the conversation list
     */
    public void addTab(Conversation c) {
        chatwin.openConversation(c);
    }

    @Override
    public void update(Observable arg0, Object arg1) {
        // TODO Auto-generated method stub
        if (arg1.equals(Val.CONNEXIONSTATE)) {
            this.chatwin = new ChatWindow(this);

        } else {
            String username = (String) arg1;
            chatwin.updateUsersList(username);
        }

    }

    public ChatWindow getChatwindow() {
        return chatwin;
    }

}
